﻿//判断用户的浏览器是不是IE，是则返回true，否则返回false
var agent = navigator.userAgent;

String.prototype.trim = function()
	{
		return this.replace(/(^[\s]*)|([\s]*$)/g, "");
	};

String.prototype.inc = function(k1, k2)
	{
		return k2 == null ? this.indexOf(k1) > -1 ? true : false : (k2 + this + k2) .indexOf(k2 + k1 + k2) > -1 ? true : false;
	};

String.prototype.toArray=function(key)
	{
		var l = this, v;
		if(key == null) key = "|";
		v = key;
		if(key == "n")
		{
			l = l.replace(/\r/g,"");
			v = "\n";
		}
		l = l.replace(new RegExp("(\\"+key+")+","g"), v).replace(new RegExp("^[\\" + key + "]*|[\\" + key + "]+$","g"), "");
		return l == "" ? new Array() : l.split(v);		
	};

Array.prototype.add = function(key)
{
	this[this.length] = key;
};



var is_Opr = agent.inc("Opera");
var is_IE = agent.inc("IE") && !is_Opr;
var is_IE4 = agent.inc("IE 4");
var is_IE5 = agent.inc("IE 5") || agent.inc("IE 4");
var is_IE5_5 = agent.inc("IE 5.5");
var is_IE6 = is_IE && !is_IE5;
var is_Moz = agent.inc("Mozilla") && !is_Opr && !is_IE;

//根据ID取对象
function oo(obj)
{
	return typeof(obj) != "string" ? obj : (is_IE5 ? document.all(obj) : document.getElementById(obj));
}

//创建对象
function co(elm)
{
	return document.createElement(elm);
}

if(is_IE4)
{
	oo=function(key){return document.all[key]}
	document.getElementsByName=function(key){var a=new Array(),ol=document.all;for(i=0;i<ol.length;i++){if(ol[i].name==key)a[a.length]=ol[i];}return a;}
	document.getElementsByTagName=function(key){var a=new Array(),ol=document.all;for(i=0;i<ol.length;i++){if(ol[i].tagName.toLowerCase()==key)a[a.length]=ol[i];}return a;}
}

if(is_Moz)
{
	Event.prototype.__defineGetter__("srcElement",function(){var node=this.target;while(node.nodeType!=1){node=node.parentNode;}return node;});
	HTMLElement.prototype.__defineGetter__("children",function(){return this.childNodes});
	HTMLElement.prototype.__defineGetter__("parentElement",function(){return this.parentNode});
}

function isIE()
{	
	return is_IE;
}

//is firefox
function isFF()
{
	return is_Moz;
}


//打印
function prtf(s)
{
	document.write(s);
}

//check type for js
function isAlien(a) 
{
	return isObject(a) && typeof a.constructor != 'function';
} 
 

function isArray(a) 
{
	return isObject(a) && a.constructor == Array;
}

function isBoolean(a)
{
	return typeof a == 'boolean';
}

function isEmpty(o) 
{
	var i, v;
	if (isObject(o)) 
	{
		for(i in o) 
		{
			v = o[i];
			if (isUndefined(v) && isFunction(v)) 
			{
				return false;
			}
		}
	}
	return true;
}

function isFunction(a) 
{
	return typeof a == 'function';
}

function isNull(a) 
{
	return typeof a == 'object' && !a;
}

function isNumber(a) 
{
	return typeof a == 'number' && isFinite(a);
}

function isObject(a) 
{
	return (a && typeof a == 'object') || isFunction(a);
}

function isString(a) 
{
	return typeof a == 'string';
}

function isUndefined(a) 
{
	return typeof a == 'undefined';
}


//convert a decimal into hex digit
function enHex(aDigit)
{
    return("0123456789ABCDEF".substring(aDigit, aDigit+1));
}

//convert a hex digit into decimal
function deHex(aDigit)
{
    return("0123456789ABCDEF".indexOf(aDigit));
}

//Convert a 24bit number to hex
function toHex(n)
{
    return (((0xf00000 & n) > 0 ? enHex((0xf00000 & n) >> 20) : "") +

            ((0x0f0000 & n) > 0 ? enHex((0x0f0000 & n) >> 16) : "") + 

            ((0x00f000 & n) > 0 ? enHex((0x00f000 & n) >> 12) : "") +

            ((0x000f00 & n) > 0 ? enHex((0x000f00 & n) >>  8) : "") +

            ((0x0000f0 & n) > 0 ? enHex((0x0000f0 & n) >>  4) : "") +

            enHex((0x00000f & n) >>  0));
}

//Convert a six character hex to decimal
function toDecimal(hexNum)
{

   	var tmp = "" + hexNum.toUpperCase();

    while (tmp.length < 6) tmp = "0" + tmp;
   
   	return ((deHex(tmp.substring(0,1)) << 20) +

       	    (deHex(tmp.substring(1,2)) << 16) + 

            (deHex(tmp.substring(2,3)) << 12) +

            (deHex(tmp.substring(3,4)) << 8) +

            (deHex(tmp.substring(4,5)) << 4) +

   	        (deHex(tmp.substring(5,6))));
}

///显示星星
//var STAR_IMG = new Array("star_00.gif", "star_11.gif", "star_10.gif", "star_01.gif", "star_20.gif", "star_02.gif");
var STAR_IMG = new Array("star_w_1.gif", "star_w_2.gif", "star_y_1.gif", "star_y_2.gif", "star_r_1.gif", "star_r_2.gif", "star_w.gif", "star_y.gif", "star_r.gif");
var K_IMG = new Array("k_w_1.gif", "k_w_2.gif", "k_y_1.gif", "k_y_2.gif", "k_r_1.gif", "k_r_2.gif", "k_w.gif", "k_y.gif", "k_r.gif");
var STAR_HINT = new Array("很糟糕", "需要改进", "马马虎虎", "还不错", "非常满意");
function returnStar(num)
{	
	var stars = "";
	for(var i = 0; i < parseInt(num / 2); i++)
	{
		stars = stars + '<img src="images/IMG/' + STAR_IMG[4] + '" border="0"/>';
		stars = stars + '<img src="images/IMG/' + STAR_IMG[5] + '" border="0"/>';
	}
	if(num < 10)
	{
		if(num % 2 != 0)
		{
			stars = stars + '<img src="images/IMG/' + STAR_IMG[4] + '" border="0"/>';
			stars = stars + '<img src="images/IMG/' + STAR_IMG[1] + '" border="0"/>';
		}

		for(var i = parseInt(num) + parseInt(num % 2); i < 10; i+=2)
		{
			stars = stars + '<img src="images/IMG/' + STAR_IMG[0] + '" border="0"/>';
			stars = stars + '<img src="images/IMG/' + STAR_IMG[1] + '" border="0"/>';
		}
	}
	return stars;
}

function shwStar(num)
{	
	var stars = returnStar(num);
	prtf(stars)
}

function returnK(num)
{	
	var k="";
	var num1 = parseInt(num / 2);
	for(var i = 0; i < num1; i++)
	{
		k = k+'<img src="images/IMG/' + K_IMG[8] + '" border="0"/>';
	}
	for(i; i < 5; i++)
	{
		k = k+'<img src="images/IMG/' + K_IMG[6] + '" border="0"/>';
	}
	return k;
}

function shwK(num)
{	
	var k = returnK(num);
	prtf(k);
}

function shwStarHint(num)
{
	num = parseInt(num);
	num = num <= 0 ? 0 : num - 1;
	return STAR_HINT[num];
}

//选择星星(用来设置分的)
//ipt 是保存的分数(input)
//shw_id 是用来显示评分评语的
function chgStar(ipt, num, shw_id)
{
	var num1 = parseInt(num / 2);
	if(num1 <= 5)
	{
		for(var i=0;i<num1;i++)
		{
			oo('star_' + i + ipt).src = 'images/IMG/' + STAR_IMG[7] ;
		}
		for(i;i<5;i++)
		{
			oo('star_' + i + ipt).src = 'images/IMG/' + STAR_IMG[6] ;
		}
  }
	oo(shw_id).innerHTML = shwStarHint(num);
}

function choStar(ipt, num, shw_id)
{
	var num1 = parseInt(num / 2);
	if(num1 <= 5)
	{
		for(var i=0;i<num1;i++)
		{
			oo('star_' + i + ipt).src = 'images/IMG/' + STAR_IMG[8] ;
		}
		for(i;i<5;i++)
		{
			oo('star_' + i + ipt).src = 'images/IMG/' + STAR_IMG[6] ;
		}
  }
	oo(ipt).value = num;
	oo(shw_id).innerHTML = shwStarHint(num);
}

function clearStar(ipt, shw_id)
{
	var num = oo(ipt).value ;
	if(num == "") num = 0;
	var num1 = parseInt(num / 2);
	if(num1 <=5)
	{
		for(var i=0;i<num1;i++)
		{
			oo('star_' + i + ipt).src = 'images/IMG/' + STAR_IMG[8] ;
		}
		for(i;i<5;i++)
		{
			oo('star_' + i + ipt).src = 'images/IMG/' + STAR_IMG[6] ;
		}
  }
	if(num == 0) oo(shw_id).innerHTML = "";
	else oo(shw_id).innerHTML = shwStarHint(num);
}

function chgK(ipt, num, shw_id)
{
	var num1 = parseInt(num);
	if(num1 <= 5)
	{
		for(var i=0;i<num1;i++)
		{
			oo('k_' + i + ipt).src = 'images/IMG/' + K_IMG[7] ;
		}
		for(i;i<5;i++)
		{
			oo('k_' + i + ipt).src = 'images/IMG/' + K_IMG[6] ;
		}
  }
	oo(shw_id).innerHTML = shwStarHint(num);
}

function choK(ipt, num, shw_id)
{
	var num1 = parseInt(num);
	if(num1 <= 5)
	{
		for(var i=0;i<num1;i++)
		{
			oo('k_' + i + ipt).src = 'images/IMG/' + K_IMG[8] ;
		}
		for(i;i<5;i++)
		{
			oo('k_' + i + ipt).src = 'images/IMG/' + K_IMG[6] ;
		}
  }
	oo(ipt).value = num;
	oo(shw_id).innerHTML = shwStarHint(num);
}

function clearK(ipt, shw_id)
{
	num = oo(ipt).value ;
	if(num == "") num = 0;
	var num1 = parseInt(num);
	if(num1 <= 5)
	{
		for(var i=0;i<num1;i++)
		{
			oo('k_' + i + ipt).src = 'images/IMG/' + K_IMG[8] ;
		}
		for(i;i<5;i++)
		{
			oo('k_' + i + ipt).src = 'images/IMG/' + K_IMG[6] ;
		}
  }
	if(num == 0) oo(shw_id).innerHTML = "";
	else oo(shw_id).innerHTML = shwStarHint(num);
}

function initChgStar(ipt, shw_id)
{
	//if(isObject(oo(ipt)))
	  prtf('<span onMouseOut="clearStar(\'' + ipt +'\', \'' + shw_id +'\')">');
		for(var i = 0; i < 5; i++)
		{
				prtf('<img src="images/IMG/' + STAR_IMG[6] + '"  border="0" id="star_' + i + ipt+ '" onMouseOver="chgStar(\'' + ipt +'\', ' + (i + 1) + ', \'' + shw_id +'\')" align="absmiddle" style="cursor:hand" onClick="choStar(\'' + ipt +'\', ' + (i + 1) + ', \'' + shw_id +'\')"/>');
		}

	prtf('</span>&nbsp;&nbsp;<span id="'+shw_id +'"></span>');
}

function initChgK(ipt, shw_id)
{
	//if(isObject(oo(ipt)))
	prtf('<span onMouseOut="clearK(\'' + ipt +'\', \'' + shw_id +'\')">');
	for(var i = 0; i < 5; i++)
	{

			prtf('<img src="images/IMG/' + K_IMG[6] + '" border="0" id="k_' + i + ipt+ '" onMouseOver="chgK(\'' + ipt +'\', ' + (i + 1) + ', \'' + shw_id +'\')" align="absmiddle" style="cursor:hand" onClick="choK(\'' + ipt +'\', ' + (i + 1) + ', \'' + shw_id +'\')"/>');
	}
	prtf('</span>&nbsp;&nbsp;<span id="'+shw_id +'"></span>');
}

function returnInitChgStar(ipt, shw_id, num)
{
	stars = '<span onMouseOut="clearStar(\'' + ipt +'\', \'' + shw_id +'\')">';
	var num1 = parseInt(num / 2);
	for(var i = 0; i < num1; i++)
	{
		stars = stars + '<img src="images/IMG/' + STAR_IMG[8] + '" border="0" id="star_' + i + ipt+ '" onMouseOver="chgStar(\'' + ipt +'\', ' + (i + 1) + ', \'' + shw_id +'\')" align="absmiddle" style="cursor:hand" onClick="choStar(\'' + ipt +'\', ' + (i + 1) + ', \'' + shw_id +'\')"/>';
	}
	for(i; i < 5; i++)
	{
		stars = stars + '<img src="images/IMG/' + STAR_IMG[6] + '" border="0" id="star_' + i + ipt+ '" onMouseOver="chgStar(\'' + ipt +'\', ' + (i + 1) + ', \'' + shw_id +'\')" align="absmiddle" style="cursor:hand" onClick="choStar(\'' + ipt +'\', ' + (i + 1) + ', \'' + shw_id +'\')"/>';
	}
  stars += '</span>&nbsp;&nbsp;<span id="'+shw_id +'"></span>';
	return stars;
}

function returnInitChgK(ipt, shw_id, num)
{
	stars = '<span onMouseOut="clearK(\'' + ipt +'\', \'' + shw_id +'\')">';
	var num1 = parseInt(num / 2);
	for(var i = 0; i < num1; i++)
	{
		stars = stars + '<img src="images/IMG/' + K_IMG[8] + '" border="0" id="k_' + i + ipt+ '" onMouseOver="chgK(\'' + ipt +'\', ' + (i + 1) + ', \'' + shw_id +'\')" align="absmiddle" style="cursor:hand" onClick="choK(\'' + ipt +'\', ' + (i + 1) + ', \'' + shw_id +'\')"/>';
	}
	for(i; i < 5; i++)
	{
		stars = stars + '<img src="images/IMG/' + K_IMG[6] + '" border="0" id="k_' + i + ipt+ '" onMouseOver="chgK(\'' + ipt +'\', ' + (i + 1) + ', \'' + shw_id +'\')" align="absmiddle" style="cursor:hand" onClick="choK(\'' + ipt +'\', ' + (i + 1) + ', \'' + shw_id +'\')"/>';
	}
  stars += '</span>&nbsp;&nbsp;<span id="'+shw_id +'"></span>';
	return stars;
}

//转换十进制到二十制
function dec2bin(dec){
bin = "";
while (dec > 0) {
if (dec%2 != 0) { bin = "1" + bin; }
else { bin = "0" + bin; }
dec = parseInt(dec/2);
}

return bin;
}
//弹出页面
function opens(url, width, height)
{
	if(width == null)width = 500;
	if(height == null)height = 400;
	var gt = unescape('%3e');
	var popup = null;
	var over = "Launch Pop-up Navigator";
	popup = window.open(url, 'popupnav', 'width='+width+',height=' + height + ',top=0,left=0,scrollbars=yes');
	if (popup != null) {
	if (popup.opener == null) {
	popup.opener = self; 
	}
	popup.location.href = url;
	}
}
function set_menu(menu_sec)
{
	menu_sec = oo("menu_sec_" + menu_sec)
	if(menu_sec)
	{
		menu_sec.className = "newsearchinsider";
	}
}



